package com.bianguo.android.tencentpushdemo.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bianguo.android.tencentpushdemo.R;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/5/27.
 */

public class CommentListAdapter extends BaseAdapter {

    private Context mContext;
    private ArrayList<String> list;
    private LayoutInflater inflater;

    public CommentListAdapter(Context mContext, ArrayList<String> list) {
        this.mContext = mContext;
        this.list = list;
        inflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return list != null ? list.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_home_layout, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.contentTv.setText(list.get(position));
        return convertView;
    }

    public static class ViewHolder{

        @BindView(R.id.item_home_text)
        TextView contentTv;

        public ViewHolder(View itemView) {
            ButterKnife.bind(this, itemView);
        }
    }
}
